package com.xcc.decoratorpattern;

import com.xcc.decoratorpattern.demo01.*;
import com.xcc.decoratorpattern.demo02.LowerCaseInputStream;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @Author xiechuang
 * @Date 2022/8/28
 */
public class Demo {

    public static void main(String[] args) {
        // 订一杯Espresso，不需要调料，打印出描述与价钱
        Beverage beverage = new Espresso();
        System.out.println(beverage.getDescription() + " $" + beverage.cost());

        // 制造出一个DarkRoast对象
        Beverage beverage2 = new DarkRoast();
        // 用Mocha装饰它
        beverage2 = new Mocha(beverage2);
        // 用第二个Mocha装饰它
        beverage2 = new Mocha(beverage2);
        // 用Whip装饰它
        beverage2 = new Whip(beverage2);
        System.out.println(beverage2.getDescription() + " $" + beverage.cost());

        Beverage beverage3 = new HouseBlend();
        beverage3 = new Soy(beverage3);
        beverage3 = new Mocha(beverage3);
        beverage3 = new Whip(beverage3);
        System.out.println(beverage3.getDescription() + " $" + beverage3.cost());


        // 双倍摩卡、豆浆、奶泡、拿铁咖啡定制
        // 制造一个HouseBlend对象
        Beverage beverage4 = new HouseBlend();
        // 用Soy装饰它
        beverage4 = new Soy(beverage4);
        // 用第一个Mocha装饰它
        beverage4 = new Mocha(beverage4);
        // 用第二个Mocha装饰它
        beverage4 = new Mocha(beverage4);
        // 用Whip装饰它
        beverage4 = new Whip(beverage4);
        System.out.println(beverage4.getDescription() + " $" + beverage4.cost());


        int c;
        try {
            // 注意：文件路径使用自己本机路径
            InputStream in = new LowerCaseInputStream(new BufferedInputStream(new FileInputStream("/Users/xiechuang/xiechuang/workspace/git/xcc-warehouse/demo/parent-demo/designpatterns-demo/src/main/java/com/xiechuang/decoratorpattern/file/test.txt")));
            while ((c = in.read()) >= 0) {
                System.out.print((char) c);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
